package Concurrency2.Chapter08_Pattern.fork_join;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

/**
 * Instruction：
 * Author：@author MaLi
 */
public class Dispatcher {
    public static void main(String[] args) {
        // 创建forkJoinPool
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        // 向Pool中提交任务
        AccumulateTask accumulateTask = new AccumulateTask(0, 100);
        ForkJoinTask<Integer> task = forkJoinPool.submit(accumulateTask);
        try {
            Integer result = task.get();
            System.out.println("ForkJoin计算结果: "+result);

        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}
